<?php
require_once("includes/prepend.php");
require_once("includes/lifesubnav.php");
$user= $page->user;

?>
<div id="maincontent"><!--start maincontent-->
	<div id="fixposition"></div>
	<div id="preinfomain">
		<ul>
			<li><h4>用户信息</h4></li>
			<li>用户账号：<?php echo $user['number'];?></li>
			<li>用户昵称：<?php echo $user['name'];?></li>
		</ul>
		<ul>
			<li><h4>更改密码</h4></li>
			<li><span>原密码：</span><input type="password" name="oldPWD" class="oldPWD" /></li>
			<li><span>新密码：</span><input type="password" name="newPWD" class="newPWD" /></li>
			<li><span>新密码确认：</span><input type="password" name="newPWDconf" class="newPWDconf" /></li>
			<li><input type="button" value="修改" name="changePWD" /></li>
		</ul>
	
	</div>
	<div id='preinfo-main-right'>
		<ul>
			<li style='width:100px;'>Last login time:</li>
			<li><?php $lastLogin = $page->getLastLogin();echo ($lastLogin['time']);?></li>
			<li style='width:100px;'>Last login IP:</li>
			<li><?php 
				if(is_array($lastLogin['ip'])){
					echo $lastLogin['ip'][0];
				}
				?>
			</li>
			<li id='all-ips' style='display:none'>
				<?php 
				if(is_array($lastLogin['ip'])){
					foreach($lastLogin['ip'] as $ip){
						echo $ip."<br />";
					}
				}
				?>
			</li>
		</ul>
	</div>
</div><!--end maincontent--->

<?php 
require_once("includes/pagefoot.php");
?>
<script>
 $(document).ready(function(){
 	$("input[name='changePWD']").click(updateUser);
 	function updateUser(){
 		var oldPwd = $("input[name='oldPWD']").val();
 		var newPwd = $("input[name='newPWD']").val();
 		var newPwdC = $("input[name='newPWDconf']").val();
 		if(HHL.trim(newPwd)==""){
 			HHL.newAlertMes("新密码不能为空！","color:red;","1500");
 			return false;
 		}
 		if(newPwd!=newPwdC){
 			HHL.newAlertMes("新密码两次输入不一致！","color:red;padding-left:20px;","1500");
 			return false;
 		}
 		 
 		var data = {"postType":1,"oldPwd":oldPwd,"newPwd":newPwd};
 		var url = "preinfo.ajax.php";
 		$.ajax({
 			type:"POST",
 			data:data,
 			url:url,
 			success:function(data){
 				if(data=="success"){
 					HHL.newAlertMes("更新成功！","color:green;","1500");
 					$("input[name='oldPWD']").val("");
 		 			$("input[name='newPWD']").val("");
 		 			$("input[name='newPWDconf']").val("");
 		 			$("input[name='oldPWD']").css({"border":""});
 		 			$("input[name='newPWD']").css({"border":""});
 		 			$("input[name='newPWDconf']").css({"border":""});
 		 			$("block").remove();
 				}else if(data=="oldpwdwrong"){
 					$("block").remove();
 					$("input[name='oldPWD']").after("<block style='color:red;'>原始密码错误</block>")
 					$("input[name='oldPWD']").css({"border":"1px red solid"})
 					HHL.newAlertMes("原始密码错误！","color:red;","1500");
 				}else {
 					HHL.newAlertMes("系统繁忙，请稍后再试！","color:red;","1500");
 				}
 			}
 		})
 		
 	}
 })
</script>
